import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class DioDemo2 extends StatefulWidget {
  const DioDemo2({super.key});


  @override
  State<DioDemo2> createState() => _DioDemoState();
}

class _DioDemoState extends State<DioDemo2> {
  @override
  void initState() {
    // 获取订单列表数据
    loadData();
    super.initState();
  }

  // 演示dio插件的基本使用
  void loadData() async {
    // 1. 准备请求地址
    const path = 'https://mock.boxuegu.com/mock/1172/orders';

    // 2. 创建http client
    Dio dio = Dio();

    // 3. 发送网络请求，得到响应
    Response response = await dio.get(path);

    // 4. 提取订单列表数据
    print(response.data);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Dio插件'),
      ),
      body: Container(
        child: const Text("134")),
    );
  }
}